#include "dialog.h"
#include "ui_dialog.h"
#include <QDebug>
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    m_index = 1;
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_m_btnPrey_clicked()
{
    if(--m_index<0){
        m_index=5;
    }
    update();//触发绘图事件
}

void Dialog::on_pushButton_2_clicked()
{
    if(++m_index>5){
        m_index=0;
    }
    update();//触发绘图事件
}

void Dialog::paintEvent(QPaintEvent *)
{
    //qDebug("painEvent");
    //(1)创建画家对象
    QPainter painter(this);
    //2)获取绘图所在矩形区域
    QRect rect = ui->frame->frameRect();
    //坐标平移，让rect和painter使用相同的坐标系
    rect.translate(ui->frame->pos());
    //3)构建要绘制图像对象
    QImage image(":/"+QString::number(m_index)+".jpeg");
    painter.drawImage(rect,image);
}
